<?php

class user_addressModel extends Model {
    
    public static function validata($data) {
        return Validation::rule(array(
            [Validation::isMust($data['name']), '姓名不能为空'],
            [Validation::isMust($data['province']), '省份不能为空'],
            [Validation::isMust($data['city']), '城市不能为空'],
            [Validation::isMust($data['address']), '详细地址不能为空'],
            [Validation::isMust($data['mobile']), '手机号不能为空'],
            [Validation::isMobile($data['mobile']), '手机号填写有误'],
            [Validation::isLength($data['address'], 1, 200), '地址长度在200字符以内']
        ));
    }
    
    public function getByIds($addressIds) {
        $sql = "select * from wf_user_address where id in ({$addressIds})";
        return $this->query($sql)->fetchAll();
    }
    
    public function deleteByIds($addressIds) {
        $sql = "delete from wf_user_address where id in ({$addressIds})";
        return $this->execute($sql);
    }
    public function formateData($data) {
        if (!$data) {
            return array();
        }
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $data[$key] = $this->formateData($value);
            } else {
                switch ($key) {
                    case 'uid':
                    case 'id':
                        $data[$key] = (int) $value;
                        break;
                    case 'is_default':
                        unset($data['is_default']);
                        $data['isDefault'] = (int) $value;
                        break;
                    default :
                        $data[$key] = (string) $value;
                }
            }
        }
        return $data;
    }


}